﻿@model User

@{
    ViewBag.Title = "" + (Model.DisplayName ?? "unknown");
}

@section HEAD{
<script src="@Url.Content("~/Content/js/application.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/js/jquery.fileupload-ui.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/js/jquery.fileupload-uix.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/js/jquery.fileupload.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Content/css/jquery.fileupload-ui.css")" rel="stylesheet" type="text/css" />
<style>
    form.file_upload input {
      position: absolute;
      top: 0;
      left:-430px;
      margin: 0;
      border: solid transparent;
      border-left-width: 200px;
      opacity: 0;
      -ms-filter: 'alpha(opacity=0)';
      filter: alpha(opacity=0);
      -o-transform: translate(200px, 0);
      -moz-transform: translate(380px, 0);
      -webkit-transform: translate(200px, 0);
      cursor: pointer;
      height: 100%;
    }
</style>
}


<div id="profile_photoCol">
	@Avatar.Large(Model, imageClass:"profile_photo")

    <div id="changeAvatar_container" class="ownerOnly">
	
	    @using (Html.BeginForm("ChangeAvatarAjax", "User", FormMethod.Post, new { enctype = "multipart/form-data", id="file_upload" }))
        {
            @Html.Hidden("id", Model.Id)
            <input type="file" name="file" />
            <button type="submit">Загрузить</button>
	        <div class="file_upload_label mouseoverShow editButton_edit">Выбрать аватар</div>
	    }
	
    
	    @if (Model.Avatar != null)
        {
		    <a href="#" class="showLightBox_link mouseoverShow editButton_delete editButton" rel="removeAvatarBox">Удалить аватар</a>
        }
        <div id="uploadErrorMessage" class="errorMessage"></div>
    </div>
	@*<span class="asButton_container profile_sendMessage">
		<!--вместо отправки e-mail сделать передачу сообщений внутри портала-->
        <a href="mailto:@Model.Email" class="asButton">Отправить сообщение</a>
	</span>*@
	<!--Пока отзывы не поддерживаются-->
    @*
	<h2>Отзывы организаторов</h2>
    <ul id="profile_organizerReviewList">
		@if (!Model.Opinions.Any())
  {
		<li class="profile_organizerReviewList_item">
			<p>нет отзывов</p>
		</li>
  }
		@foreach (Opinion op in Model.Opinions)
  {
			<li class="profile_organizerReviewList_item">
			@Avatar.Small(op.Author, imageClass:"person_image")
				<span class="profile_organizerReview_subject">
					@op.Text
					<!--внедрить like-->
					<a href="#" class="socialButton socialButton_facebook">162 человека</a>
				</span>
			</li>
		}
    </ul>*@
</div>

<div id="profile_infoCol_outer"><div id="profile_infoCol">
    <h1>@(Model.DisplayName ?? "unknown")</h1>
    <dl id="profile_infoList">
        <dt>Интересы:</dt>
        <dd>@Data.Render(Model.Interests, "Не указаны")</dd>
        <dt>Умения:</dt>
        <dd>@Data.Render(Model.Skills, "Не указаны")</dd>
		<dt>Эл. почта:</dt>
        @if (Model.HideEmail && !(ViewBag.EditMode || ViewBag.IsAdmin))
        {
            <dd>Не указана</dd>
        }
        else
        {
		    <dd>@Email.Render(Model.NotificationEmail, "Не указана")</dd>
        }
		@if (ViewBag.EditMode || ViewBag.IsAdmin) 
		{
			<dt>Основной Email:</dt>
			<dd>@Email.Render(Model.Email, "Не указана")</dd>
		}
        <dt>Другие контакты:</dt>
        <dd>
            <ul id="profile_contactList">
                <li class="profile_contactList_item">@Data.Render(Model.Contacts, "Не указаны")</li>
            </ul>
        </dd>
        @if (ViewBag.EditMode)
        {
		<dt>
			<a href="javascript:void(0)" class="showLightBox_link mouseoverShow editButton_edit editButton" rel="editProfileBox">Редактировать</a>
        
		</dt>
            if (Model.AccountSource == AccountSource.GoodWorx)
            {
            <dt>
                <a href="javascript:void(0)" class="showLightBox_link mouseoverShow editButton_edit editButton" rel="passwordBox">Сменить пароль</a>
            </dt>
            }
        }
    </dl>
    <table class="profile_projectsList">
        <thead>
            <tr>
                <th colspan="3">Ближайшие проекты</th>
            </tr>
        </thead>
        @{Html.RenderAction<ProjectController>(x => x.IndexUpcomingForUser(Model));}
        <thead>
            <tr>
                <th colspan="3">Завершенные проекты</th>
            </tr>
        </thead>
		@{Html.RenderAction<ProjectController>(x => x.IndexFinishedForUser(Model));}
    </table>
</div></div>
@Html.Partial("UpdateProfileView", new Web.ViewModels.UserProfileModel()
{
	Id = Model.Id,
	DisplayName = Model.DisplayName,
	NotificationEmail = Model.NotificationEmail,
	Skills = Model.Skills,
	Interests = Model.Interests,
	Contacts = Model.Contacts
})
    <div class="lightbox" id="passwordBox">
    	<a href="#" class="lightbox_close">Закрыть</a>	
		@using (Html.BeginForm<UserController>(x => x.ChangePassword(0, null, null, null), 
      FormMethod.Post, 
      new { @class = "ajaxForm", id = "passwordBoxForm" }))
  {
		<fieldset>
            <input type="hidden" name="Id" value="@Model.Id" />
			<label for="oldPassword">Текущий пароль: </label>
            <input type="password" class="requiredField" name="oldPassword" id="oldPassword"/>
            <br />
            <label for="newPassword">Новый пароль: </label>
            <input type="password" class="requiredField" name="newPassword" id="newPassword"/>
            <br />
            <label for="newPassword2">Повторите новый пароль: </label>
            <input type="password" class="requiredField" name="newPassword2" id="newPassword2"/>
			<br />
		</fieldset>
		<div id="errorMessage" class="errorMessage"></div>
		@Html.SubmitButton(null, "Отправить")
  }
	</div>
<div id="lightbox_shadow">&nbsp;</div>
<div class="lightbox" id="removeAvatarBox">
    <a href="#" class="lightbox_close">Закрыть</a>
 @using (Html.BeginForm("RemoveAvatar", "User", FormMethod.Post))
 {
	<fieldset>
		@Html.Hidden("id", Model.Id)
	</fieldset>
	 <p>Вы уверены, что хотите удалить аватар?</p>
	 
	@Html.SubmitButton(null, "Удалить")
 }
</div>

<script type="text/javascript">
    $(document).ready(function () {
        $('#file_upload').fileUploadUI(
            'option',
            {
                onLoad: function (event, files, index, xhr, handler) {
                    var json;
                    if (xhr.responseText != undefined) {
                        json = $.parseJSON(xhr.responseText);
                    } else {
                        // Instead of an XHR object, an iframe is used for legacy browsers:
                        json = $.parseJSON(xhr.contents().text());
                    }
                    if (json.code == 200) {
                        window.location.reload();
                    } else {
                        $("#uploadErrorMessage").html(json.message);
                    }
                    /* ... */
                },
                onError: function (event, files, index, xhr, handler) {
                    // For JSON parsing errors, the load event is saved as handler.originalEvent:
                    var json;
                    if (handler.originalEvent) {
                        json = $.parseJSON(xhr.responseText);
                    } else {
                        json = $.parseJSON(xhr.contents().text());
                    }
                }
            }
        );
        $('#passwordBoxForm')[0].success = xxx($('#passwordBoxForm'));
        function xxx(jf) {
            return function success(data) {
                if (data != null && data.ErrorMessage != null)
                    jf.children(".errorMessage").html(data.ErrorMessage);
                else {
                    $('#lightbox_shadow').click();
                    window.location = data.RedirectUrl;
                }
            };
        }
    });
//    $("#changeAvatar_link").click(function () {
//        $(this).hide();
//        $("#changeAvatar_container").slideToggle();
//        return false;
//    });

//    $("#changeAvatar_reset").click(function () {
//        $("#changeAvatar_container").slideToggle();
//        $("#changeAvatar_link").show();
//        return false;
//    });
</script>
